package cn.bdqn.tools;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class RedisUtils {
    @Resource
    private RedisTemplate<String ,Object> redisTemplate;
    /**
     * 往redis中存数据
     * @param key 键
     * @param value 值
     * @return 是否存成功
     */
    public boolean set(String key,Object value){
        ValueOperations<String,Object> vo=redisTemplate.opsForValue();
        vo.set(key,value);
        return true;
    }

    /**
     * 向redis中获取数据
     * @param key 键
     * @return 值
     */
    public Object get(String key){
        ValueOperations<String,Object> vo=redisTemplate.opsForValue();
        return vo.get(key);
    }

    /**
     * 根据key删除redis中数据
     * @param key 键
     * @return 是否成功
     */
    public boolean del(String key){
        redisTemplate.delete(key);
        return true;
    }
}
